/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.coupon.controller;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.log.annotation.SysLog;
import com.ykht.proj.common.security.util.SecurityUtils;
import com.ykht.proj.coupon.entity.FxBarrage;
import com.ykht.proj.coupon.entity.FxComment;
import com.ykht.proj.coupon.service.FxCommentService;
import com.ykht.proj.coupon.vo.FxCommentVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


/**
 * 资讯评价表
 *
 * @author proj code generator
 * @date 2021-07-07 16:20:00
 */
@RestController
@AllArgsConstructor
@RequestMapping("/fxcomment" )
@Api(value = "fxcomment", tags = "资讯评价表管理")
@Slf4j
public class FxCommentController {

    private final  FxCommentService fxCommentService;

    /**
     * 资讯评价表 分页查询
     * @param page 分页对象
     * @param fxCommentVo 资讯评价表
     * @return
     */
    @ApiOperation(value = "资讯评价表 分页查询", notes = "资讯评价表 分页查询")
    @GetMapping("/page" )
    public R<IPage<FxCommentVo>> getFxCommentPage(Page page, FxCommentVo fxCommentVo) {
		log.info("->资讯评价表 分页查询:{}", JSONUtil.toJsonStr(fxCommentVo));
		IPage<FxCommentVo> iPage = fxCommentService.getFxCommentPage(page, fxCommentVo);
        return R.ok(iPage);
    }

	/**
	 * pc 审核评论
	 * @param fxCommentVo 资讯评价表
	 * @return R
	 */
	@ApiOperation(value = "pc 审核评论", notes = "pc 审核评论")
	@SysLog("pc 审核评论" )
	@PostMapping("updateFxComment")
	public R updateFxComment(@RequestBody FxCommentVo fxCommentVo) {
		log.info("->pc 审核评论:{}", JSONUtil.toJsonStr(fxCommentVo));
		fxCommentVo.setUpdateUser(SecurityUtils.getUserId());
		fxCommentVo.setUpdateTime(LocalDateTime.now());
		fxCommentVo.setApprovalDate(LocalDateTime.now());
		fxCommentService.updateFxComment(fxCommentVo);
		return R.ok();
	}


    /**
     * 通过id查询资讯评价表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('coupon_fxcomment_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(fxCommentService.getById(id));
    }

    /**
     * 新增资讯评价表
     * @param fxComment 资讯评价表
     * @return R
     */
    @ApiOperation(value = "新增资讯评价表", notes = "新增资讯评价表")
    @SysLog("新增资讯评价表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('coupon_fxcomment_add')" )
    public R save(@RequestBody FxComment fxComment) {
        return R.ok(fxCommentService.save(fxComment));
    }

    /**
     * 修改资讯评价表
     * @param fxComment 资讯评价表
     * @return R
     */
    @ApiOperation(value = "修改资讯评价表", notes = "修改资讯评价表")
    @SysLog("修改资讯评价表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('coupon_fxcomment_edit')" )
    public R updateById(@RequestBody FxComment fxComment) {
        return R.ok(fxCommentService.updateById(fxComment));
    }

    /**
     * 通过id删除资讯评价表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除资讯评价表", notes = "通过id删除资讯评价表")
    @SysLog("通过id删除资讯评价表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('coupon_fxcomment_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(fxCommentService.removeById(id));
    }

}
